//
//  MallCommentTableViewCell.m
//  CYWFrame
//
//  Created by Macx on 2017/9/1.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "MallCommentTableViewCell.h"
#import "GoodsComment.h"
#import "NSString+Common.h"

@implementation MallCommentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    CGSize size1 = [LZCTools textSizeWithText:@"x" font:kUHSystemFontWithSize(10)];
    
    self.headPic.frame = CGRectMake(10, 10, SW(10), SW(10));
    self.headPic.layer.cornerRadius = SW(20);
    self.headPic.layer.masksToBounds = YES;
    
    self.nickName.font = kUHSystemFontWithSize(10);
    self.nickName.frame = CGRectMake(self.headPic.x+self.headPic.width+5, self.headPic.centerY-size1.height, SCREEN_WIDTH-self.nickName.x, size1.height);
    
    self.date.font = kUHSystemFontWithSize(10);
    self.date.frame = CGRectMake(self.nickName.x, self.headPic.y+self.headPic.height-size1.height, self.nickName.width, size1.height);
    
    self.content.font = kUHSystemFontWithSize(11);
    self.content.numberOfLines = 0;
    
}

- (void)setModel:(GoodsComment *)model {
    if (_model != model) {
        _model = model;
        
        [self.headPic sd_setImageWithURL:[NSURL URLWithString:[model.user valueForKey:@"face"]] placeholderImage:IMAGE(@"placeHolder")];
        self.nickName.text = [model.user valueForKey:@"nickname"];
        self.date.text = [NSString timeWithTimeIntervalString:[NSString stringWithFormat:@"%ld", model.create_time]];
        
        self.content.text = model.body;
        CGRect rect = [self.content.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-20, NSIntegerMax) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.content.font} context:nil];
        self.content.frame = CGRectMake(10, self.headPic.y+self.headPic.height+5, rect.size.width, rect.size.height);
        
        self.height = self.content.y+self.content.height+10;
        
        for (int i = 0; i < model.pics.count; i++) {
            UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(10+(SW(5)+10)*i, self.content.height+self.content.y+5, SW(5), SW(5))];
            [self addSubview:img];
            [img sd_setImageWithURL:[NSURL URLWithString:model.pics[i]] placeholderImage:IMAGE(@"placeHolder")];
            
            self.height = img.y+img.height+10;
        }
        
    }
}

- (CGFloat)cellHeight {
    return self.height;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
